﻿using System;
using DBHelper;
using SME.Food.Surperise.BLL;
using SME.Food.Surperise.Model;

namespace SME.Food.Tricon.Web.AdminJS.MemberManage
{
    public partial class MemberH : System.Web.UI.Page
    {

        public Bas_Member_BLL bll = new Bas_Member_BLL();
        public Bas_Member_Model model = new Bas_Member_Model();
        public string forwardUrl = "MemberManage/MemberList.aspx";
        protected void Page_Load(object sender, EventArgs e)
        {
            string Mem_No = Request["Mem_No"];
            string type = Request.QueryString["type"];
            string hid = Request.Form["hid"];
            if (type == "modify")
            {
                if (hid == "add")
                {
                    Modify(0);
                }
                if (hid == "update")
                {

                    Modify(1);
                }
            }

            else if (type == "delete")
            {
                if (bll.DeleteList(Mem_No))
                {
                    Common.DwzMessage(true, true, "MemberList", "MemberList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");
                }
            }
            else if (type == "deleteAll")
            {
                Mem_No = Request["ids"];
                if (bll.DeleteList(Mem_No))
                {

                    Common.DwzMessage(true, true, "MemberList", "MemberList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, false, " ", " ", " ");
                }
            }
        }

        public void Modify(int i)
        {
            model.Mem_Name = Request.Form["Mem_Name"];
            model.Mem_Sex = Int32.Parse(Request.Form["Mem_Sex"]);
            model.Mem_Card = Request.Form["Num_Card"];
            model.Mem_Type = Int32.Parse(Request.Form["PostSelect"]);
            if (i == 0)
            {
                model.Mem_No = DbHelperSQL.GetMaxID("Mem_No", "Bas_Member").ToString();
                if (bll.Add(model) > 0)
                {
                    //Response.Write("<script>alertMsg.correct('操作成功！'); </script>");
                    //Response.Write("<script> alert('操作成功！');window.location='MemberManage/MemberList.aspx';</script> ");
                    // Common.DwzMessage(true, true, "MemberList", "MemberList", "AdminJS/MemberManage/MemberList.aspx");
                    Response.Write("{'statusCode':'200', 'message':'操作成功' , 'navTabId':'MemberList','rel':'MemberList', 'callbackType':'closeCurrent', 'forwardUrl':'" + forwardUrl + "'}");
                    Response.End();
                    //Common.DwzMessage(true, true, "MemberList", "MemberList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, true, " ", " ", " ");

                }
            }
            if (i == 1)
            {
                model.Mem_No = Request.Form["Mem_No"];
                if (bll.Update(model))
                {
                    Common.DwzMessage(true, true, "MemberList", "MemberList", forwardUrl);
                }
                else
                {
                    Common.DwzMessage(false, true, " ", " ", " ");
                }


            }




        }
    }
}